/**
 * 应用常量定义
 * 包含应用中使用的各种常量值
 */

/**
 * 应用基础常量
 */
export const APP_CONSTANTS = {
  NAME: 'ReactIM H5',
  VERSION: '1.0.0',
  DESCRIPTION: 'ReactIM H5 即时通讯客户端',
  AUTHOR: 'ReactIM Team',
  
  // 存储键前缀
  STORAGE_PREFIX: 'reactim_',
  
  // 默认配置 - 使用base64编码的默认头像避免404错误
  DEFAULT_AVATAR: '',
  DEFAULT_GROUP_AVATAR: '',
  
  // 分页配置
  PAGE_SIZE: {
    MESSAGES: 20,
    CONVERSATIONS: 50,
    FRIENDS: 100,
    SEARCH_RESULTS: 20
  }
} as const

/**
 * 消息相关常量
 */
export const MESSAGE_CONSTANTS = {
  // 消息类型
  TYPE: {
    TEXT: 'TEXT',
    IMAGE: 'IMAGE',
    FILE: 'FILE',
    VOICE: 'VOICE',
    VIDEO: 'VIDEO',
    LOCATION: 'LOCATION',
    SYSTEM: 'SYSTEM'
  },
  
  // 消息状态
  STATUS: {
    SENDING: 'SENDING',
    SENT: 'SENT',
    DELIVERED: 'DELIVERED',
    READ: 'READ',
    FAILED: 'FAILED'
  },
  
  // 消息限制
  LIMITS: {
    TEXT_MAX_LENGTH: 5000,
    FILE_MAX_SIZE: 100 * 1024 * 1024, // 100MB
    IMAGE_MAX_SIZE: 20 * 1024 * 1024, // 20MB
    VOICE_MAX_DURATION: 60, // 60秒
    VIDEO_MAX_SIZE: 200 * 1024 * 1024, // 200MB
    VIDEO_MAX_DURATION: 300 // 5分钟
  },
  
  // 支持的文件类型
  SUPPORTED_TYPES: {
    IMAGE: ['image/jpeg', 'image/png', 'image/gif', 'image/webp', 'image/svg+xml'],
    AUDIO: ['audio/mp3', 'audio/wav', 'audio/ogg', 'audio/m4a', 'audio/aac'],
    VIDEO: ['video/mp4', 'video/webm', 'video/ogg', 'video/avi', 'video/mov'],
    DOCUMENT: [
      'application/pdf',
      'application/msword',
      'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
      'application/vnd.ms-excel',
      'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
      'application/vnd.ms-powerpoint',
      'application/vnd.openxmlformats-officedocument.presentationml.presentation',
      'text/plain'
    ]
  }
} as const

/**
 * 用户相关常量
 */
export const USER_CONSTANTS = {
  // 用户状态
  STATUS: {
    ONLINE: 'online',
    OFFLINE: 'offline',
    AWAY: 'away',
    BUSY: 'busy',
    INVISIBLE: 'invisible'
  },
  
  // 用户角色
  ROLE: {
    USER: 'user',
    ADMIN: 'admin',
    MODERATOR: 'moderator'
  },
  
  // 用户信息限制
  LIMITS: {
    USERNAME_MIN_LENGTH: 3,
    USERNAME_MAX_LENGTH: 20,
    NICKNAME_MAX_LENGTH: 50,
    PASSWORD_MIN_LENGTH: 6,
    PASSWORD_MAX_LENGTH: 128,
    BIO_MAX_LENGTH: 200
  }
} as const

/**
 * 会话相关常量
 */
export const CONVERSATION_CONSTANTS = {
  // 会话类型
  TYPE: {
    PRIVATE: 'PRIVATE',
    GROUP: 'GROUP',
    SYSTEM: 'SYSTEM'
  },
  
  // 群组限制
  GROUP_LIMITS: {
    MAX_MEMBERS: 500,
    NAME_MAX_LENGTH: 50,
    DESCRIPTION_MAX_LENGTH: 200
  }
} as const

/**
 * 网络相关常量
 */
export const NETWORK_CONSTANTS = {
  // 超时配置
  TIMEOUT: {
    REQUEST: 10000, // 10秒
    UPLOAD: 60000, // 60秒
    DOWNLOAD: 30000, // 30秒
    WEBSOCKET_CONNECT: 5000 // 5秒
  },
  
  // 重试配置
  RETRY: {
    MAX_ATTEMPTS: 3,
    DELAY: 1000, // 1秒
    BACKOFF_FACTOR: 2
  },
  
  // WebSocket配置
  WEBSOCKET: {
    RECONNECT_INTERVAL: 3000, // 3秒
    MAX_RECONNECT_ATTEMPTS: 5,
    HEARTBEAT_INTERVAL: 30000, // 30秒
    HEARTBEAT_TIMEOUT: 5000 // 5秒
  },
  
  // RSocket配置
  RSOCKET: {
    KEEP_ALIVE: 60000, // 60秒
    LIFETIME: 180000, // 3分钟
    MAX_FRAME_SIZE: 1024 * 1024, // 1MB
    SETUP_TIMEOUT: 5000 // 5秒
  }
} as const

/**
 * UI相关常量
 */
export const UI_CONSTANTS = {
  // 主题
  THEME: {
    LIGHT: 'light',
    DARK: 'dark',
    AUTO: 'auto'
  },
  
  // 语言
  LANGUAGE: {
    ZH_CN: 'zh-CN',
    EN_US: 'en-US'
  },
  
  // 响应式断点
  BREAKPOINTS: {
    MOBILE: 768,
    TABLET: 1024,
    DESKTOP: 1200
  },
  
  // 动画持续时间
  ANIMATION: {
    FAST: 150,
    NORMAL: 300,
    SLOW: 500
  },
  
  // Z-index层级
  Z_INDEX: {
    DROPDOWN: 1000,
    MODAL: 1050,
    POPOVER: 1060,
    TOOLTIP: 1070,
    NOTIFICATION: 1080
  },
  
  // 颜色主题
  COLORS: {
    PRIMARY: '#409EFF',
    SUCCESS: '#67C23A',
    WARNING: '#E6A23C',
    DANGER: '#F56C6C',
    INFO: '#909399',
    TEXT_PRIMARY: '#303133',
    TEXT_REGULAR: '#606266',
    TEXT_SECONDARY: '#909399',
    TEXT_PLACEHOLDER: '#C0C4CC',
    BORDER_BASE: '#DCDFE6',
    BORDER_LIGHT: '#E4E7ED',
    BORDER_LIGHTER: '#EBEEF5',
    BORDER_EXTRA_LIGHT: '#F2F6FC',
    BACKGROUND_BASE: '#F5F7FA'
  }
} as const

/**
 * 错误码常量
 */
export const ERROR_CONSTANTS = {
  // 通用错误
  COMMON: {
    UNKNOWN: 'UNKNOWN_ERROR',
    NETWORK: 'NETWORK_ERROR',
    TIMEOUT: 'TIMEOUT_ERROR',
    PARSE: 'PARSE_ERROR',
    VALIDATION: 'VALIDATION_ERROR'
  },
  
  // 认证错误
  AUTH: {
    INVALID_CREDENTIALS: 'INVALID_CREDENTIALS',
    TOKEN_EXPIRED: 'TOKEN_EXPIRED',
    TOKEN_INVALID: 'TOKEN_INVALID',
    UNAUTHORIZED: 'UNAUTHORIZED',
    FORBIDDEN: 'FORBIDDEN'
  },
  
  // 消息错误
  MESSAGE: {
    SEND_FAILED: 'MESSAGE_SEND_FAILED',
    RECEIVE_FAILED: 'MESSAGE_RECEIVE_FAILED',
    INVALID_FORMAT: 'INVALID_MESSAGE_FORMAT',
    TOO_LARGE: 'MESSAGE_TOO_LARGE',
    UNSUPPORTED_TYPE: 'UNSUPPORTED_MESSAGE_TYPE'
  },
  
  // 文件错误
  FILE: {
    TOO_LARGE: 'FILE_TOO_LARGE',
    UNSUPPORTED_TYPE: 'UNSUPPORTED_FILE_TYPE',
    UPLOAD_FAILED: 'FILE_UPLOAD_FAILED',
    DOWNLOAD_FAILED: 'FILE_DOWNLOAD_FAILED'
  },
  
  // 连接错误
  CONNECTION: {
    FAILED: 'CONNECTION_FAILED',
    LOST: 'CONNECTION_LOST',
    TIMEOUT: 'CONNECTION_TIMEOUT',
    REFUSED: 'CONNECTION_REFUSED'
  }
} as const

/**
 * 事件名称常量
 */
export const EVENT_CONSTANTS = {
  // 用户事件
  USER: {
    LOGIN: 'user:login',
    LOGOUT: 'user:logout',
    STATUS_CHANGE: 'user:status_change',
    PROFILE_UPDATE: 'user:profile_update'
  },
  
  // 消息事件
  MESSAGE: {
    SEND: 'message:send',
    RECEIVE: 'message:receive',
    READ: 'message:read',
    DELETE: 'message:delete',
    TYPING: 'message:typing'
  },
  
  // 连接事件
  CONNECTION: {
    CONNECT: 'connection:connect',
    DISCONNECT: 'connection:disconnect',
    RECONNECT: 'connection:reconnect',
    ERROR: 'connection:error'
  },
  
  // 会话事件
  CONVERSATION: {
    CREATE: 'conversation:create',
    UPDATE: 'conversation:update',
    DELETE: 'conversation:delete',
    JOIN: 'conversation:join',
    LEAVE: 'conversation:leave'
  }
} as const

/**
 * 正则表达式常量
 */
export const REGEX_CONSTANTS = {
  // 用户名：3-20位字母数字下划线
  USERNAME: /^[a-zA-Z0-9_]{3,20}$/,
  
  // 密码：至少6位，包含字母和数字
  PASSWORD: /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d@$!%*#?&]{6,}$/,
  
  // 邮箱
  EMAIL: /^[^\s@]+@[^\s@]+\.[^\s@]+$/,
  
  // 手机号（中国大陆）
  PHONE: /^1[3-9]\d{9}$/,
  
  // URL
  URL: /^https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)$/,
  
  // IP地址
  IP: /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/,
  
  // 表情符号
  EMOJI: /[\u{1F600}-\u{1F64F}]|[\u{1F300}-\u{1F5FF}]|[\u{1F680}-\u{1F6FF}]|[\u{1F1E0}-\u{1F1FF}]|[\u{2600}-\u{26FF}]|[\u{2700}-\u{27BF}]/gu
} as const

/**
 * 本地存储键名常量
 */
export const STORAGE_KEYS = {
  // 用户相关
  USER_INFO: 'user_info',
  AUTH_TOKEN: 'auth_token',
  REFRESH_TOKEN: 'refresh_token',
  
  // 应用设置
  APP_THEME: 'app_theme',
  APP_LANGUAGE: 'app_language',
  APP_VERSION: 'app_version',
  
  // 聊天相关
  CHAT_SETTINGS: 'chat_settings',
  LAST_CONVERSATION: 'last_conversation',
  MESSAGE_DRAFTS: 'message_drafts',
  
  // 通知设置
  NOTIFICATION_SETTINGS: 'notification_settings',
  
  // 缓存
  FRIENDS_CACHE: 'friends_cache',
  CONVERSATIONS_CACHE: 'conversations_cache'
} as const

/**
 * API路径常量
 */
export const API_PATHS = {
  // 认证相关
  AUTH: {
    LOGIN: '/api/auth/login',
    LOGOUT: '/api/auth/logout',
    REFRESH: '/api/auth/refresh',
    REGISTER: '/api/auth/register'
  },
  
  // 用户相关
  USER: {
    PROFILE: '/user/profile',
    FRIENDS: '/user/friends',
    SEARCH: '/user/search',
    STATUS: '/user/status'
  },
  
  // 消息相关
  MESSAGE: {
    SEND: '/message/send',
    HISTORY: '/message/history',
    READ: '/message/read',
    DELETE: '/message/delete'
  },
  
  // 会话相关
  CONVERSATION: {
    LIST: '/conversation/list',
    CREATE: '/conversation/create',
    UPDATE: '/conversation/update',
    DELETE: '/conversation/delete'
  },
  
  // 文件相关
  FILE: {
    UPLOAD: '/file/upload',
    DOWNLOAD: '/file/download',
    DELETE: '/file/delete'
  }
} as const

// 导出所有常量
export default {
  APP: APP_CONSTANTS,
  MESSAGE: MESSAGE_CONSTANTS,
  USER: USER_CONSTANTS,
  CONVERSATION: CONVERSATION_CONSTANTS,
  NETWORK: NETWORK_CONSTANTS,
  UI: UI_CONSTANTS,
  ERROR: ERROR_CONSTANTS,
  EVENT: EVENT_CONSTANTS,
  REGEX: REGEX_CONSTANTS,
  STORAGE_KEYS,
  API_PATHS
}